package com.fz.controller;

import com.fz.common.Result;
import com.fz.controller.request.BorrowPageRequest;
import com.fz.pojo.Borrow;
import com.fz.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/borrow")
@CrossOrigin
public class BorrowController {
    @Autowired
    private BorrowService borrowService;

    //查询用户
    @GetMapping("/list")
    public Result list() {
        List<Borrow> borrow = borrowService.list();
        return Result.success(borrow);
    }

    //通过id查询种类
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Borrow borrow = borrowService.getById(id);
        return Result.success(borrow);
    }

    //分页
    @GetMapping("/page")
    public Result page(BorrowPageRequest borrowPageRequest) {
        return Result.success(borrowService.page(borrowPageRequest));
    }


    // 添加
    @PostMapping("/addBorrow")
    public Result addBorrow(@RequestBody Borrow borrow) {//这里要加@RequestBody 如果不加添加都是null
        borrowService.addBorrow(borrow);
        return Result.success();
    }

    //更新
    @PutMapping("/update")
    public Result update(@RequestBody Borrow borrow) {
        borrowService.update(borrow);
        return Result.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        borrowService.deleteById(id);
        return Result.success();
    }
    


}
